<template>
  <!-- 打印预览弹窗 -->
  <div class="preview-box" >
    <div id="myPrint">
        <slot></slot>
    </div>
    <div style="text-align: center; margin-top: 100px">
      <el-button type="primary" @click="printNotice">打印</el-button>
      <el-button @click="closePreview">关闭</el-button>
    </div>
  </div>
</template>

<script>
import { reactive, toRefs } from "vue";
import printJS from "print-js";
export default {
    props:['printStyle'],
  setup(props,ct5) {
    const state = reactive({
      count: 0,
    });

    function printNotice(params) {
      printJS({
        printable: "myPrint", // 标签元素id
        type: "html",
        header: "",
        targetStyle: '*',
	    targetStyles: '*',
        
        scanStyles: false,
        style:props.printStyle,
      });
    }

    function closePreview(params) {
      ct5.emit('closePreview')
    };

    return {
      ...toRefs(state),
      printNotice,closePreview
    };
  },
};
</script>

<style lang="scss" scoped>

.preview-box {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
  z-index: 10;
  background-color: #fff;
  padding: 20px;
  overflow: auto;
}


</style>